package com.sugou.model.commons;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.Table;

import com.sugou.model.commons.embeddable.Pixels;

/**
 * 图片库
 * @author 童弘成
 */
@Entity(name="ImagesLibrary")
@Table(name="US_IMAGES_LIBRARY")
public class ImagesLibrary extends LobLibrary {
	private static final long serialVersionUID = -2665449956405051701L;
	
	/**
	 * 图片像素尺寸
	 */
	@Embedded
	private Pixels pixels;
	
	/**
	 * 虚拟文件名称,为空则与id相同
	 */
	@Column(length=64,nullable=true)
	private String fileName;
	
	/**
	 * 图片文件实体
	 */
	@Column(nullable=false)
	@Lob
	@Basic(fetch=FetchType.LAZY)
	private byte[] body;

	public ImagesLibrary() {
		super();
	}

	public ImagesLibrary(Long id) {
		super();
		this.setId(id);
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public byte[] getBody() {
		return body;
	}

	public void setBody(byte[] body) {
		this.body = body;
	}

	@Override
	public InputStream getBodyStream() {
		return new ByteArrayInputStream(this.getBody());
	}

	public Pixels getPixels() {
		return pixels;
	}

	public void setPixels(Pixels pixels) {
		this.pixels = pixels;
	}
	
	
}
